package cn.humaohua.study.yanmo_design_pattern.ch12.v3;

public class WaterQuality extends WaterQualitySubject {
    // 污染级别
    private int polluteLevel;

    public void setPolluteLevel(int polluteLevel) {
        this.polluteLevel = polluteLevel;
        notifyObservers();
    }

    @Override
    protected void notifyObservers() {
        for (WatcherObserver observer : observers) {
            if (this.polluteLevel >= 0) {
                // 通知监测员做记录
                if ("监测人员".equals(observer.getJob())) {
                    observer.update(this);
                }
            }

            if (this.polluteLevel >= 1) {
                // 通知预警人员
                if ("预警人员".equals(observer.getJob())) {
                    observer.update(this);
                }
            }

            if (this.polluteLevel >= 2) {
                // 通知监测部门领导
                if ("监测部门领导".equals(observer.getJob())) {
                    observer.update(this);
                }
            }
        }

    }

    @Override
    protected int getPolluteLevel() {
        return polluteLevel;
    }

}
